// $('.mobileNo').html(getdata.MobileNo);
$('.identityNo').html(theRequest.IdentityNo);
$('.user-right').html('李四');
//血压最新数据
var HeartRateLength = 0;
var TemperatureLength = 0;
var GlucoseLength = 0;
var OxygenLength = 0;
var PulseLength = 0;
var LeftSystolicLength = 0;
var LeftDiastolicLength = 0;
var RightSystolicLength = 0;
var RightDiastolicLength = 0;
$.ajax({
    url: `${Url}/Wechat/Api/LatestNewBP?IdentityNo=${theRequest.IdentityNo}`,
    type: 'get',
    datatype: 'json',
    headers: {
        'Authorization': Authorization
    },
    async: false,
    success: function(res) {
        if (res.code == 200) {

            for (const key in res.data.ExamItems) {
                if (res.data.ExamItems[key].NewBP.PulseRate >= 60 && res.data.ExamItems[key].NewBP.PulseRate <= 100) {
                    $('.examModel .pulseRate').html(res.data.ExamItems[key].NewBP.PulseRate);
                    $('.erro .pulseRate').parent('tr').css('display', 'none')
                } else {
                    $('.erro .pulseRate').html(res.data.ExamItems[key].NewBP.PulseRate);
                    $('.examModel .pulseRate').parent('tr').css('display', 'none')
                }


                if (res.data.ExamItems[key].NewBP.LeftSystolic >= 90 && res.data.ExamItems[key].NewBP.LeftSystolic <= 140) {
                    $('.examModel .leftSystolic').html(res.data.ExamItems[key].NewBP.LeftSystolic);
                    $('.erro .leftSystolic').parent('tr').css('display', 'none');
                    LeftSystolicLength = 0
                } else {
                    $('.erro .leftSystolic').html(res.data.ExamItems[key].NewBP.LeftSystolic);
                    $('.examModel .leftSystolic').html(res.data.ExamItems[key].NewBP.LeftSystolic);
                    $('.examModel .leftSystolic').addClass('caution');
                    LeftSystolicLength = 1
                }


                if (res.data.ExamItems[key].NewBP.RightSystolic >= 90 && res.data.ExamItems[key].NewBP.RightSystolic <= 140) {
                    $('.examModel .rightSystolic').html(res.data.ExamItems[key].NewBP.RightSystolic);
                    $('.erro .rightSystolic').parent('tr').css('display', 'none');
                    RightSystolicLength = 0
                } else {
                    $('.erro .rightSystolic').html(res.data.ExamItems[key].NewBP.RightSystolic);
                    $('.examModel .rightSystolic').html(res.data.ExamItems[key].NewBP.RightSystolic);
                    $('.examModel .rightSystolic').addClass('caution');
                    RightSystolicLength = 1
                }


                if (res.data.ExamItems[key].NewBP.LeftDiastolic >= 60 && res.data.ExamItems[key].NewBP.LeftDiastolic <= 90) {
                    $('.examModel .leftDiastolic').html(res.data.ExamItems[key].NewBP.LeftDiastolic);
                    $('.erro .leftDiastolic').parent('tr').css('display', 'none');
                    LeftDiastolicLength = 0
                } else {
                    $('.erro .leftDiastolic').html(res.data.ExamItems[key].NewBP.LeftDiastolic);
                    $('.examModel .leftDiastolic').html(res.data.ExamItems[key].NewBP.LeftDiastolic);
                    // $('.examModel .leftDiastolic').parent('tr').css('display', 'none');
                    $('.examModel .leftDiastolic').addClass('caution');
                    LeftDiastolicLength = 1
                }


                if (res.data.ExamItems[key].NewBP.RightDiastolic >= 60 && res.data.ExamItems[key].NewBP.RightDiastolic <= 90) {
                    $('.examModel .rightDiastolic').html(res.data.ExamItems[key].NewBP.RightDiastolic);
                    $('.erro .rightDiastolic').parent('tr').css('display', 'none');
                    RightDiastolicLength = 0
                } else {
                    $('.erro .rightDiastolic').html(res.data.ExamItems[key].NewBP.RightDiastolic);
                    // $('.examModel .rightDiastolic').parent('tr').css('display', 'none');
                    $('.examModel .rightDiastolic').html(res.data.ExamItems[key].NewBP.RightDiastolic);
                    $('.examModel .leftDiastolic').addClass('caution');
                    RightDiastolicLength = 1
                }
                if (res.data.ExamItems[key].NewBP.LeftSystolic >= 90 && res.data.ExamItems[key].NewBP.LeftSystolic <= 140 && res.data.ExamItems[key].NewBP.RightSystolic >= 90 && res.data.ExamItems[key].NewBP.RightSystolic <= 140 && res.data.ExamItems[key].NewBP.LeftDiastolic >= 60 && res.data.ExamItems[key].NewBP.LeftDiastolic <= 90 && res.data.ExamItems[key].NewBP.RightDiastolic >= 60 && res.data.ExamItems[key].NewBP.RightDiastolic <= 90) {
                    $('.examModel .newBp').css('display', 'block');
                    $('.erro .newBp').css('display', 'none');
                } else {
                    $('.erro .newBp').css('display', 'block');
                    // $('.examModel .newBp').css('display', 'none');
                }

                $('.newBp .CheckDate').html(res.data.ExamItems[key].NewBP.CheckDate);
            }
            $('.user-right').html(res.data.FullName)
        } else {
            $('.newBp').css('display', 'none')
        }
    }
});
//血糖最新数据
$.ajax({
    url: `${Url}/Wechat/Api/LatestBloodGlucose?IdentityNo=${theRequest.IdentityNo}`,
    type: 'get',
    datatype: 'json',
    headers: {
        'Authorization': Authorization
    },
    async: false,
    success: function(res) {

        if (res.code == 200) {
            for (const key in res.data.ExamItems) {
                if (res.data.ExamItems[key].BloodGlucose.Glucose >= 3.61 && res.data.ExamItems[key].BloodGlucose.Glucose <= 6.11) {
                    $('.examModel .glucose').html(res.data.ExamItems[key].BloodGlucose.Glucose);
                    $('.erro .bloodGlucose').css('display', 'none');
                    GlucoseLength = 0
                } else {
                    $('.erro .glucose').html(res.data.ExamItems[key].BloodGlucose.Glucose);
                    $('.examModel .glucose').html(res.data.ExamItems[key].BloodGlucose.Glucose);
                    $('.examModel .glucose').addClass('caution')
                        // $('.examModel .bloodGlucose').css('display', 'none');
                    GlucoseLength = 1
                }
                $('.bloodGlucose .CheckDate').html(res.data.ExamItems[key].BloodGlucose.CheckDate);
                if (res.data.ExamItems[key].BloodGlucose.Glucose >= 3.61 && res.data.ExamItems[key].BloodGlucose.Glucose <= 6.11) {
                    $('.examModel .bloodGlucose').css('display', 'block');
                    $('.erro .bloodGlucose').css('display', 'none');
                } else {
                    $('.erro .bloodGlucose').css('display', 'block');
                    // $('.examModel .bloodGlucose').css('display', 'none');
                }
            }
        } else {
            $('.bloodGlucose').css('display', 'none');
        }
        // $('.user-right').html(res.data.FullName)
    }
});
//最新血氧数据  /Wechat/Api/LatestOxygenLevel
$.ajax({
    url: `${Url}/Wechat/Api/LatestOxygenLevel?IdentityNo=${theRequest.IdentityNo}`,
    type: 'get',
    datatype: 'json',
    headers: {
        'Authorization': Authorization
    },
    async: false,
    success: function(res) {
        if (res.code == 200) {
            for (const key in res.data.ExamItems) {

                if (res.data.ExamItems[key].OxygenLevel.Pulse >= 60 && res.data.ExamItems[key].OxygenLevel.Pulse <= 100) {
                    $('.examModel .pulse').html(res.data.ExamItems[key].OxygenLevel.Pulse);
                    $('.erro .pulse').parent('tr').css('display', 'none');
                    PulseLength = 0
                } else {
                    $('.erro .pulse').html(res.data.ExamItems[key].OxygenLevel.Pulse);
                    $('.examModel .pulse').html(res.data.ExamItems[key].OxygenLevel.Pulse);
                    $('.examModel .pulse').addClass('caution');
                    // $('.examModel .pulse').parent('tr').css('display', 'none');
                    PulseLength = 1
                }

                if (res.data.ExamItems[key].OxygenLevel.Oxygen >= 97 && res.data.ExamItems[key].OxygenLevel.Oxygen <= 100) {
                    $('.examModel .oxygen').html(res.data.ExamItems[key].OxygenLevel.Oxygen);
                    $('.erro .oxygen').parent('tr').css('display', 'none');
                    OxygenLength = 0
                } else {
                    $('.erro .oxygen').html(res.data.ExamItems[key].OxygenLevel.Oxygen);
                    $('.examModel .oxygen').html(res.data.ExamItems[key].OxygenLevel.Oxygen);
                    $('.examModel .oxygen').addClass('caution');
                    // $('.examModel .oxygen').parent('tr').css('display', 'none');
                    OxygenLength = 1
                }


                if (res.data.ExamItems[key].OxygenLevel.Oxygen >= 97 && res.data.ExamItems[key].OxygenLevel.Oxygen <= 100 && res.data.ExamItems[key].OxygenLevel.Pulse >= 60 && res.data.ExamItems[key].OxygenLevel.Pulse <= 100) {
                    $('.examModel .oxygenLevel').css('display', 'block');
                    $('.erro .oxygenLevel').css('display', 'none');
                } else {
                    $('.erro .oxygenLevel').css('display', 'block');
                    // $('.examModel .oxygenLevel').css('display', 'none');
                }

                $('.oxygenLevel .CheckDate').html(res.data.ExamItems[key].OxygenLevel.CheckDate);
                $('.oxygen').html(res.data.ExamItems[key].OxygenLevel.Oxygen);
            }
        } else {
            $('.oxygenLevel').css('display', 'none')
        }
    }
});
//最新体温数据
$.ajax({
    url: `${Url}/Wechat/Api/LatestTemperature?IdentityNo=${theRequest.IdentityNo}`,
    type: 'get',
    datatype: 'json',
    headers: {
        'Authorization': Authorization
    },
    async: false,
    success: function(res) {
        if (res.code == 200) {
            for (const key in res.data.ExamItems) {

                if (res.data.ExamItems[key].Temperature.Temperature >= 35.8 && res.data.ExamItems[key].Temperature.Temperature <= 37.8) {
                    $('.examModel .Temperature').html(res.data.ExamItems[key].Temperature.Temperature);
                    $('.erro .Temperature').parent('tr').css('display', 'none');
                    TemperatureLength = 0
                } else {
                    $('.erro .Temperature').html(res.data.ExamItems[key].Temperature.Temperature);
                    $('.examModel .Temperature').parent('tr').css('display', 'none');
                    TemperatureLength = 1
                }
                if (res.data.ExamItems[key].Temperature.Temperature >= 35.8 && res.data.ExamItems[key].Temperature.Temperature <= 37.8) {
                    $('.examModel .temperature').css('display', 'block');
                    $('.erro .temperature').css('display', 'none');
                } else {
                    $('.erro .temperature').css('display', 'block');
                    $('.examModel .temperature').css('display', 'none');
                }

                $('.temperature .CheckDate').html(res.data.ExamItems[key].Temperature.CheckDate);
                $('.Temperature').html(res.data.ExamItems[key].Temperature.Temperature);
                // $('.oxygen').html(res.data.ExamItems[key].OxygenLevel.Oxygen);

            }
        } else {
            $('.temperature').css('display', 'none')
        }
    }
});
//最新心电数据
$.ajax({
    url: `${Url}/Wechat/Api/LatestECG?IdentityNo=${theRequest.IdentityNo}`,
    type: 'get',
    datatype: 'json',
    headers: {
        'Authorization': Authorization
    },
    async: false,
    success: function(res) {
        var title = {}
        if (res.code == 200) {
            for (const key in res.data.ExamItems) {

                var ECG = res.data.ExamItems[key].ECG;
                $('.ecg .CheckDate').html(ECG.CheckDate);
                if (ECG.EcgResult.includes("-1")) {
                    $('.EcgResult').append('未检测');
                    // $('.EcgResult').prepend('未检测');
                }
                if (ECG.EcgResult.includes("0")) {
                    $('.EcgResult').append('窦性心律正常心电图');
                }
                if (ECG.EcgResult.includes("1")) {
                    $('.EcgResult').append('早搏异常心电图');

                }
                if (ECG.EcgResult.includes("2")) {
                    $('.EcgResult').append('漏搏异常心电图');
                }
                if (ECG.EcgResult.includes("3")) {
                    $('.EcgResult').append('停搏异常心电图');
                }
                if (ECG.EcgResult.includes("4")) {
                    $('.EcgResult').append('室性二连律异常心电图');
                }
                if (ECG.EcgResult.includes("5")) {
                    $('.EcgResult').append('室性三联律异常心电图');
                }
                if (ECG.EcgResult.includes("6")) {
                    $('.EcgResult').append('室性心动过速异常心电图');
                }
                if (ECG.EcgResult.includes("7")) {
                    $('.EcgResult').append('心动过速异常心电图');
                }
                if (ECG.EcgResult.includes("8")) {
                    $('.EcgResult').append('心动过缓异常心电图');
                }
                if (ECG.EcgResult.includes("9")) {
                    $('.EcgResult').append('插入室早异常心电图');
                }
                if (ECG.EcgResult.includes("10")) {
                    $('.EcgResult').append('室性早搏异常心电图');
                }
                if (ECG.EcgResult.includes("11")) {
                    $('.EcgResult').append('房性早搏异常心电图');
                }
            }
        } else {
            $('.ecg').css('display', 'none')
        }
    }
});
var result = HeartRateLength + TemperatureLength + GlucoseLength + OxygenLength + PulseLength + LeftSystolicLength + LeftDiastolicLength + RightSystolicLength + RightDiastolicLength
$('ul li span').html(result)
    //tab按钮
$('ul li').click(function() {
    if ($(this).index() == 0) {
        $('.erro').css('display', 'none');
        $('.examModel').css('display', 'block');
        $(this).next().removeClass('color');
        $(this).addClass('color');

    } else {
        $('.erro').css('display', 'block');
        $('.examModel').css('display', 'none');
        $(this).prev().removeClass('color');
        $(this).addClass('color');

    }
})